<!--  -->
<template>
  <div class="top flex column grow">
    <yn-title>
      <template slot="icon">
        <img
          src="../images/clzb.png"
          @error="imageHandler(path + '/client/ylHome/images/clzb.png', $event)"
        />
      </template>
    </yn-title>
    <div class="content flex column grow" ref="wrap">
      <div class="noMore flex column grow" v-if="tableDate.length == 0">
        <div class="noMoreBg">暂无数据</div>
      </div>
      <div class="list flex column grow" v-if="tableDate.length > 0">
        <div
          class="item"
          v-for="item in tableDate"
          :key="item.id"
          @click="link"
        >
          <i class="circle"></i>
          <p class="time">{{ item.pubtime }}</p>
          <div class="txt">
            <p>
              {{ item.content }}
            </p>
          </div>
        </div>
      </div>
    </div>
    <div class="inRoom shrink" @click="link"></div>
  </div>
</template>

<script>
import { queryByRoomid, broadcastingList } from "../api/index";
import * as fn from "../script/utils";
import { CLIENT } from "@/common/const";

export default {
  data() {
    return {
      roomid: "",
      tableDate: [],
      path: CLIENT,
      imageHandler: fn.imageHandler,
    };
  },

  components: {},

  computed: {},

  mounted() {
    this.queryByRoomid();
  },

  methods: {
    link() {
      window.prompt(
        "",
        `up://["user.info",${Date.now()},{"type":"goto-text-live","data":{}}]`
      );
    },
    async queryByRoomid() {
      await queryByRoomid({
        productId: window.localStorage.getItem("productId"),
      }).then((back) => {
        if (back.status == 1) {
          let data = back.data;
          this.roomid = data;
          this.broadcastingList();
        }
      });
    },
    async broadcastingList() {
      const { token } = fn.getUrlParams();
      await broadcastingList({
        clientCentralToken: token,
        roomid: this.roomid,
      }).then((back) => {
        if (back.status == 1) {
          let list = back.data.list;
        }
      });
      this.tableDate = list.map((item) => {
        item.content = item.content.replace(/<.+?>/g, function (value) {
          if (value.indexOf("img") != -1) {
            return "[图片]";
          } else {
            return "";
          }
        });
        item.pubtime = fn.timeFormat(item.pubtime);
        return item;
      });
      this.putDown();
    },
    putDown() {
      this.$nextTick(() => {
        const box = this.$refs.wrap;
        box.scrollTop = box.scrollHeight;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.top {
  height: 56%;
  border: 1px solid #323337;
  .inRoom {
    width: 232px;
    height: 55px;
    margin: 0 auto;
    background: url(../images/jr_btn.png) no-repeat;
  }
}
.content {
  overflow-y: auto;
  .noMore {
    flex-direction: row; /* 子元素横向排列 */
    justify-content: center; /* 相对父元素水平居中 */
    align-items: center; /*  子元素相对父元素垂直居中 */
    .noMoreBg {
      color: #bcbfc4;
      font-size: 16px;
    }
  }
}
.list {
  padding-bottom: 5px;
  box-sizing: border-box;
  .item {
    margin: 0 20px 0 12px;
    border-left: 1px dashed #a6805d;
    padding: 17px 0 0 22px;
    position: relative;
    box-sizing: content-box;
    .circle {
      display: inline-block;
      width: 11px;
      height: 11px;
      border: 2px solid #a6805d;
      background: #1c1d21;
      box-sizing: border-box;
      border-radius: 50%;
      position: absolute;
      top: 19px;
      left: -6.5px;
    }
    .time {
      color: #bd9069;
      font-size: 16px;
      font-weight: 400;
    }
    .txt {
      margin-top: 12px;
      position: relative;
      color: #bcbfc4;
      font-size: 16px;
      font-weight: 400;
      background: #25262a;
      border: 1px solid #323337;
      line-height: 40px;
      cursor: pointer;
      padding: 0 17px;
      p {
        width: 100%;
        overflow: hidden;
        box-sizing: border-box;
        text-overflow: ellipsis;
        white-space: nowrap;
      }

      &:before {
        content: "";
        position: absolute !important;
        width: 16px;
        height: 16px;
        border: 1px solid #323337;
        background: #25262a;
        -webkit-transform: rotate(-45deg);
        -moz-transform: rotate(-45deg);
        -ms-transform: rotate(-45deg);
        -o-transform: rotate(-45deg);
        transform: rotate(-45deg);
        left: -10px;
        top: 12px;
        border-right: 0px;
        border-bottom: 0px;
      }
      &:hover {
        background: #323337;
        color: #d6dadf;
        box-shadow: 0px 4px 5px 0px rgba(5, 5, 6, 0.45);
        &:before {
          background: #323337;
          box-shadow: -4px -2px 5px 0px rgba(5, 5, 6, 0.45);
        }
      }
    }
  }
}
</style>
